﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SN.Services;
using SN.Data;
using SN.Models;
namespace SN.Report
{
    public partial class FormChooseClass : Form
    {
        public r_ReportClass Classes;

        public FormChooseClass()
        {
            InitializeComponent();
        }

        private void FormChooseClass_Load(object sender, EventArgs e)
        {
            //UI.Hourglass(true);
            SNService.Hourglass(true);
            try
            {
                List<r_ReportClass> ClassesList = (List<r_ReportClass>)SN.Data.DBUtility.DB.From<r_ReportClass>().ToList();
                foreach (r_ReportClass item in ClassesList)
                {
                    TreeNode Pnode = new TreeNode() { Text = item.Class_Name, Tag = item.Class_Id };
                    Pnode.ImageIndex = 0;
                    Pnode.SelectedImageIndex = 1;
                    treeView1.Nodes.Add(Pnode);
                }
            }
            catch (Exception err)
            {
                SNService.Hourglass(false);
                SNService.ShowError(err.Message);
            }
            finally
            {
                SNService.Hourglass(false);
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node != null)
            {
                Classes = DBUtility.DB.From<r_ReportClass>().Where(r_ReportClass._.Class_Id == e.Node.Tag.ToString()).ToSingle();
            }
        }
    }
}
